const MyPromise = require('./MyPromise');

/*链式*/
// const promise = new MyPromise((resolve, reject) => {
//     resolve('success')
// }).then(
//     val => console.log(val),
//     reason => console.log(reason)
// ).then(
//     val => console.log(111),
//     reason => console.log(reason)
// );

/*回调*/
// const promise2 = new MyPromise((resolve, reject) => {
//     setTimeout(() => {
//         resolve('success')
//     }, 2000)
// }).then(
//     val => console.log(val),
//     reason => console.log(reason)
// );


// catch 异步，返回promise对象
// const p1 = new Promise(function (resolve, reject) {
//     setTimeout(() => reject(new Error('fail')), 3000)
// });

// const p2 = new Promise(function (resolve, reject) {
//     setTimeout(() => resolve(p1), 1000)
// });

// p2.then(result => console.log(result)).catch(error => console.log(error))


// all race
// const promise5 = new MyPromise((resolve, reject) => {
//     resolve('success')
// }).then(res => console.log(res))
// const s1 = MyPromise.all([p1, p2, 'p3']);
// const s2 = MyPromise.all([ promise5, 'p3']);
// const s3 = Promise.race([p1, p2, promise5])


//resolve reject
// let p11 = Promise.resolve('123');
// p11.then(function(value) {
//     console.log(value); // 123
// });
// let p12 = Promise.reject('error');
// p12.then(function(value) {
//     console.log(value);
// }, error => console.log(error));
